




Namespace Ventas
    Public Class Comprobante



        Public Function Combo(ByVal vTodos As Boolean, Optional ByVal vmensaje As String = "Todos") As Entity.Ventas.ComprobanteCol
            Dim objCol As New entity.Ventas.ComprobanteCol
            Dim obj As New Data.Ventas.Comprobante
            objCol = obj.Listar("", _
              -1, _
              "", _
              0, _
              -1, _
              "", _
              -1, _
              "", _
              "", _
              -1, _
              0.0, _
              0.0, _
              0.0, _
              0.0, _
              0.0, _
              -1, _
              -1)
            If vTodos Then
                Dim ent As New Entity.Ventas.Comprobante( _
                  -1, _
                  vmensaje, _
                  0, _
                  -1, _
                  "", _
                  -1, _
                  "", _
                  "", _
                  -1, _
                  0.0, _
                  0.0, _
                  0.0, _
                  0.0, _
                  0.0, _
                  -1, _
                  -1)
                objCol.AddPrimero(ent)
            End If
            Return objCol
        End Function


        '***************************


        Public Function Listar(ByVal ComprobanteId As Integer) As Entity.Ventas.Comprobante

            Dim objEnt As New entity.Ventas.Comprobante
            Dim obj As New Data.Ventas.Comprobante
            Return obj.Listar(ComprobanteId)

        End Function


        '***************************



        Public Function Listar( _
          ByVal ComprobanteId As Integer, _
          ByVal Codigo As String, _
          ByVal Fecha As Long, _
          ByVal ClienteId As Integer, _
          ByVal ClienteObs As String, _
          ByVal TipoId As Integer, _
          ByVal Serie As String, _
          ByVal Nro As String, _
          ByVal PagoTipoId As Integer, _
          ByVal SubTotal As Double, _
          ByVal TotalDescuento As Double, _
          ByVal IGv As Double, _
          ByVal Redondeo As Double, _
          ByVal Total As Double, _
          ByVal Cantidad As Integer, _
          ByVal Estado As Integer) _
        As Entity.Ventas.ComprobanteCol

            Dim objCol As New entity.Ventas.ComprobanteCol
            Dim obj As New Data.Ventas.Comprobante
            Return obj.listar("", _
              ComprobanteId, _
              Codigo, _
              Fecha, _
              ClienteId, _
              ClienteObs, _
              TipoId, _
              Serie, _
              Nro, _
              PagoTipoId, _
              SubTotal, _
              TotalDescuento, _
              IGv, _
              Redondeo, _
              Total, _
              Cantidad, _
              Estado)

        End Function


        '***************************


        Public Function Grabar( _
          ByVal ComprobanteId As Integer, _
          ByVal Codigo As String, _
          ByVal Fecha As Long, _
          ByVal ClienteId As Integer, _
          ByVal ClienteObs As String, _
          ByVal TipoId As Integer, _
          ByVal Serie As String, _
          ByVal Nro As String, _
          ByVal PagoTipoId As Integer, _
          ByVal SubTotal As Double, _
          ByVal TotalDescuento As Double, _
          ByVal IGv As Double, _
          ByVal Redondeo As Double, _
          ByVal Total As Double, _
          ByVal Cantidad As Integer, _
          ByVal Estado As Integer, _
        ByVal vUSuario As Integer) As Integer

            Dim _codigo As Integer = -1
            Dim obj As New Data.Ventas.Comprobante
            If ComprobanteId = -1 Then
                _codigo = obj.insert("", _
                  ComprobanteId, _
                  Codigo, _
                  Fecha, _
                  ClienteId, _
                  ClienteObs, _
                  TipoId, _
                  Serie, _
                  Nro, _
                  PagoTipoId, _
                  SubTotal, _
                  TotalDescuento, _
                  IGv, _
                  Redondeo, _
                  Total, _
                  Cantidad, _
                  Estado, _
                 vUSuario)
            Else
                _codigo = obj.update("", _
                  ComprobanteId, _
                  Codigo, _
                  Fecha, _
                  ClienteId, _
                  ClienteObs, _
                  TipoId, _
                  Serie, _
                  Nro, _
                  PagoTipoId, _
                  SubTotal, _
                  TotalDescuento, _
                  IGv, _
                  Redondeo, _
                  Total, _
                  Cantidad, _
                  Estado, _
                 vUSuario)
            End If
            Return _codigo

        End Function


        '***************************


        Public Function Insertar( _
          ByVal ComprobanteId As Integer, _
          ByVal Codigo As String, _
          ByVal Fecha As Long, _
          ByVal ClienteId As Integer, _
          ByVal ClienteObs As String, _
          ByVal TipoId As Integer, _
          ByVal Serie As String, _
          ByVal Nro As String, _
          ByVal PagoTipoId As Integer, _
          ByVal SubTotal As Double, _
          ByVal TotalDescuento As Double, _
          ByVal IGv As Double, _
          ByVal Redondeo As Double, _
          ByVal Total As Double, _
          ByVal Cantidad As Integer, _
          ByVal Estado As Integer, _
        ByVal vUSuario As Integer) As Integer

            Dim _codigo As Integer = -1
            Dim obj As New Data.Ventas.Comprobante
            _codigo = obj.insert("", _
              ComprobanteId, _
              Codigo, _
              Fecha, _
              ClienteId, _
              ClienteObs, _
              TipoId, _
              Serie, _
              Nro, _
              PagoTipoId, _
              SubTotal, _
              TotalDescuento, _
              IGv, _
              Redondeo, _
              Total, _
              Cantidad, _
              Estado, _
             vUSuario)
            Return _codigo

        End Function


        '***************************


        Public Function Updatear( _
          ByVal ComprobanteId As Integer, _
          ByVal Codigo As String, _
          ByVal Fecha As Long, _
          ByVal ClienteId As Integer, _
          ByVal ClienteObs As String, _
          ByVal TipoId As Integer, _
          ByVal Serie As String, _
          ByVal Nro As String, _
          ByVal PagoTipoId As Integer, _
          ByVal SubTotal As Double, _
          ByVal TotalDescuento As Double, _
          ByVal IGv As Double, _
          ByVal Redondeo As Double, _
          ByVal Total As Double, _
          ByVal Cantidad As Integer, _
          ByVal Estado As Integer, _
        ByVal vUSuario As Integer) As Integer

            Dim _codigo As Integer = -1
            Dim obj As New Data.Ventas.Comprobante
            _codigo = obj.Update("", _
              ComprobanteId, _
              Codigo, _
              Fecha, _
              ClienteId, _
              ClienteObs, _
              TipoId, _
              Serie, _
              Nro, _
              PagoTipoId, _
              SubTotal, _
              TotalDescuento, _
              IGv, _
              Redondeo, _
              Total, _
              Cantidad, _
              Estado, _
             vUSuario)
            Return _codigo

        End Function


        '***************************


        Public Function ELiminar(ByVal ComprobanteId As Integer, ByVal vusuario As Integer, Optional ByVal vopcion As String = "Delete") As Integer
            Dim _codigo As Integer = -1
            Dim obj As New Data.Ventas.Comprobante
            _codigo = obj.Eliminar("vopcion", ComprobanteId, vusuario)
            Return _codigo

        End Function

        Public Function ValidarRegistroDetalle(ByVal vComprobanteID As Integer, _
                                               ByVal vCantidad As Integer, _
                                               ByVal vtotal As Integer) As String
            Dim _bol As Boolean = True
            Dim _str As String = ""

            Dim obj As New Data.Ventas.Comprobante
            Dim ent As Entity.Ventas.Comprobante

            ent = obj.ValidarPostInsert(vComprobanteID)

            If ent.Total <> vtotal Then
                _bol = False
            End If

            If ent.Cantidad <> vCantidad Then
                _bol = False
            End If


            If ent.Codigo = "" Then
                _bol = False
            End If

            If _bol = True Then
                _str = ent.Codigo
            End If

            Return _str




        End Function



    End Class



End Namespace

